<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>过滤器</title>
</head>

<body>
    <div id="app">
        <h2>显示格式化的日期事时间</h2>
        <p>{{date}}</p>
        <p>完整版{{date | dateStr}}</p>
        <p>年月日{{date | dateStr('YYYY-MM-DD')}}</p>
        <p>时分秒{{date | dateStr('HH:mm:ss')}}</p>
    </div>
    <script src="https://cdn.bootcss.com/vue/2.5.16/vue.js"></script>
    <script src="https://cdn.bootcss.com/moment.js/2.22.1/moment.js"></script>
    <script>
        //自定义过滤器
        Vue.filter('dateStr', function (value, format) {
            return moment(value).format(format || 'YYYY-MM-DD, HH:mm:ss')
        })
        new Vue({
            el: '#app',
            data: {
                date: new Date()
            }
        })
    </script>
</body>

</html>